﻿import { Component, OnInit}from "@angular/core";
import { Hero}from './hero';
import { HeroService} from './hero.service';
import {Router} from "@angular/router";
@Component({
    moduleId: module.id,
    selector: "my-dashboard",
    //template: '<h3>My Dashboard</h3>'//替换为以下url
    templateUrl: 'dashboard.component.html',
    styleUrls: ['dashboard.component.css']
})
export class DashboardComponent implements OnInit {
    heroes: Hero[] = [];

    constructor(
        private router: Router,
        private heroService: HeroService) {
    }

    ngOnInit(): void {
         this.heroService.getHeroes()
      .then(r => this.heroes = r.slice(0, 4));
    }

    gotoDetail(hero: Hero): void {
        let link = ['/detail', hero.id];
        this.router.navigate(link);
    }
}